<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html lang="cn" class="app">
<head>
    <meta charset="utf-8" />
    <title>${dict:getConfigValueByKey('WEB_NAME','管理平台')} | 单位管理</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="icon" type="image/png" href="icon.png">
    <link rel="apple-touch-icon-precomposed" href="icon.png">
    <link rel="stylesheet" href="${ctxStatic}/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/app.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/ztree/css/zTreeStyle.css">
    <%--<link rel="stylesheet" href="${ctxStatic}/js/page/paging.css" type="text/css" />--%>
    <!--[if lt IE 9]>
    <script src="${ctxStatic}/js/ie/html5shiv.js"></script>
    <script src="${ctxStatic}/js/ie/respond.min.js"></script>
    <script src="${ctxStatic}/js/ie/excanvas.js"></script>
    <![endif]-->
</head>
<body>
<section class="scrollable wrapper">
    <div class="row">
        <div class="col-lg-12">
            <!-- 引导开始 -->
            <ul class="breadcrumb">
                <li><a href="${ctx}/welcome"><i class="fa fa-home"></i> 主页</a></li>
                <li>系统设置</li>
                <li class="active">单位管理</li>
            </ul>
            <!-- 引导结束 -->
        </div>
    </div>

    <div class="col-sm-3" style="overflow: auto">
        <%--<c:choose>--%>
            <%--<c:when test="${organizationList==null || organizationList.size() ==0 }">--%>
                <%--<div style="padding:20px;width:100%;text-align: center">没有权限范围内的数据</div>--%>
            <%--</c:when>--%>
            <%--<c:otherwise>--%>
                <style>.line{height:auto;}</style><%--这个不能删除--%>
                <ul id="tree" class="ztree" style="min-width: 300px;"></ul><!-- 资源树 -->
            <%--</c:otherwise>--%>
        <%--</c:choose>--%>
    </div>

    <div class="col-sm-9">
        <section class="panel panel-default">
            <%--操作区域 开始--%>
            <div class="row wrapper">
                <div class="col-sm-5 m-b-xs">
                    <button class="btn btn-sm btn-default" onclick="addOrg();">新增</button>
                    <%--<button class="btn btn-sm btn-default" onclick="updateTree();">整理单位层级关系</button>--%>
                </div>
                <div class="col-sm-4 m-b-xs">
                </div>
                <%--搜索区域--%>
                <div class="col-sm-3">
                    <input id="treeNode" type="hidden" value="${loginUser.orgId}"/>
                    <%--<div class="input-group">--%>
                    <%--<input id="searchKey" type="text" class="input-sm form-control" placeholder="输入关键词">--%>
                    <%--<span class="input-group-btn">--%>
                    <%--<button onclick="searchPage(1);" class="btn btn-sm btn-default" type="button">搜索</button>--%>
                    <%--</span>--%>
                    <%--</div>--%>
                </div>
            </div>
            <%--操作区域 结束--%>

            <div class="table-responsive">
                <table class="table table-striped b-t b-light">
                    <thead>
                    <tr>
                        <th class="text-center" style="width:60px;"></th>
                        <th class="text-center" >名称</th>
                        <th class="text-center" >归属</th>
                        <%--<th class="text-center" width="22%">评估模板</th>--%>
                        <th class="text-center" >可用</th>
                        <th class="text-center" >操作</th>
                    </tr>
                    </thead>
                    <tbody id="tplView">

                    </tbody>
                </table>
            </div>

            <footer class="panel-footer">
                <div class="row">
                    <%--分页--%>
                    <div id="page" class="col-sm-12 text-right text-center-xs"></div>
                </div>

            </footer>

        </section>
    </div>
</section>

</body>
<script src="${ctxStatic}/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="${ctxStatic}/js/bootstrap.js"></script>
<!-- App -->
<script type="text/javascript" src="${ctxStatic}/js/tools.js?version=${ctxVersion}"></script>
<script type="text/javascript" src="${ctxStatic}/js/page/paging.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tmpl/jquery.tmpl.js"></script>
<script src="${ctxStatic}/js/ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layui/layui.all.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/table2excel/jquery.table2excel.js"></script>
<%--加载分页总表数据--%>
<script id="tplHtml" type="text/x-jquery-tmpl">
    {{if results && results.length>0}}
        {{each results}}
        <tr>
            <td class="text-center" >{{= ($index+1)+(pageNo-1)*10}}</td>
            <td class="text-left" >{{= name}}</td>
            <td class="text-center">{{= organization.name}}</td>
            <%--<td class="text-center">{{= templateNm}}</td>--%>
            <td class="text-center" >{{if available}}<span class="label label-success">可用</span>{{else}}<span class="label label-danger">禁用</span>{{/if}}</td>
            <td class="text-center">
                <a href="javascript:;" onclick="openModel('','${ctx}/organization/update?id={{= id }}',true,true)" class="btn btn-sm btn-info">编辑</a>
                <a href="${ctx}/organization/delete?id={{= id }}" onclick="return confirm('确认要删除该条数据吗？', this.href)" title="删除" class="btn btn-sm btn-danger">删除</a>
            </td>
        </tr>
        {{/each}}
    {{else}}
        <tr><td colspan="5" class="text-center" >暂无数据</td></tr>
    {{/if}}
</script>
<script>
    $(function(){
        searchPage(1);//默认查第一级的资源
        loadTree();
    })
    //查询分页数据
    function searchPage(num){
        var parentId = $("#treeNode").val();
        var label = $("#searchKey").val();
        var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
        $.ajax({
            type: 'post',
            url: '${ctx}/organization/getPage.json?timeStamp='+new Date().getTime(),
            dataType:"json",
            data: {"pageNo":num,"pageSize":$("#paging_js_page_size").val(),"id":parentId},
            success: function (data) {
                layer.close(loadingLayer);
                var page = data.data;
                $( "#tplView" ).empty();
                $( "#tplHtml" ).tmpl( data.data ).appendTo( "#tplView" );

                //分页
                $("#page").paging({
                    pageNo:page.pageNo,
                    totalPage: page.totalPage,
                    totalSize: page.totalRecord,
                    callback: function(num) {
                        searchPage(num);
                    }
                })

            },error:function(){
                layer.close(loadingLayer);
                showMsg("点击过快或程序异常");
            }
        });
    }

    /** 加载组织机构树 */
    function loadTree(){
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback : {
                onClick : function(event, treeId, treeNode) {
                    <%--location.href = "${ctx}/organization?id="+treeNode.id;--%>
                    $("#treeNode").val(treeNode.id);
                    searchPage(1);
                },
                onAsyncSuccess :function(){
                    //zTreeObj.expandAll(true);
                    showztreemenuNum(true,zTreeObj,3);
                }
            }
        };
        // 查询所有权限菜单
        $.ajax({
            type: 'get',
            url: '${ctx}/organization/getMyOrgList.json?timeStamp='+new Date().getTime(),
            dataType:"json",
            data: {},
            success: function (data) {
                var list = data.data;
                var zNodes = [];
                for(var i=0;i<list.length;i++){
                    zNodes[i] = {
                        id: list[i].id,
                        pId: list[i].parentId,
                        name: list[i].name,
                        open: 1
                    };
                }
                $.fn.zTree.init($("#tree"), setting, zNodes);
            },error:function(){
                showMsg("点击过快或程序异常");
            }
        });
    }

    /**进入添加页面*/
    function addOrg(){
        openModel(false,'${ctx}/organization/create?id='+$("#treeNode").val());
    }
    /**执行单位层级关系整理*/
    function updateTree(){
        layer.confirm('确认进行整理层级关系吗？<br/><span class="text-danger">(注：如果从数据库直接添加数据，则需要通过此功能进行整理层级关系)</span>', {
            btn: ['确认提交','取消'] //按钮
        }, function(){
            var loadingLayer = layer.msg('正在整理中，请耐心等待...', {icon: 16,shade: 0.01});
            $.ajax({
                type: 'post',
                url: '${ctx}/organization/updateTree.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: {},
                success: function (data) {
                    layer.close(loadingLayer);
                    if(data.ret == "1"){
                        showMsg(data.desc,function(){
                            window.location.reload();
                        });
                    }else{
                        showMsg(data.desc);
                    }
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }, function(){

        });



    }
</script>
</html>
